package com.lagou.edu.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import com.lagou.edu.util.MailUtils;

/**
 * 该类用于模拟，我们要使用共享的那些配置信息做一些事情
 */
@RestController
@RequestMapping("/email")
@RefreshScope
public class EmailController {
    @Value("${email.host}")
    private String host;
    @Value("${email.protocol}")
    private String protocol;
    @Value("${email.from}")
    private String from;
    @Value("${email.fromPassword}")
    private String fromPassword;
    @Value("${email.subject}")
    private String subject;

    @RequestMapping(value = "/sendCode",method=
            RequestMethod.POST)
    public void sendCode(@RequestParam(value = "code")String code,@RequestParam(value = "email")String email) {
        try {
            MailUtils mailUtils = new MailUtils(host,protocol,from,fromPassword,email,subject,"内容是什么呢？",code);
            mailUtils.send();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
